var CORE = new core();
function onload(){
	CORE.init();
	new visu1();
	new visu2();
}

function core(){
	var Self = this;
	this.Element;
	this.Input;
	this.Playlist;
	this.MediaLib;
	this.Transport;
	this.ResourceController;
	this.Websocket;
	
	var Listeners  	= {
			onPlay:[],
			onPause: [],
			onStop: [],
			onPrev: [],
			onStateChanged: [],
			onPositionChanged: [],
			onEndOfMediaItem: [], // ???
			//etc  .... bauen wir erst rein wenn wir sie brauchen
	};
	
	this.init = function(){
		//initialize classes
		this.Element = $("#mainSection");
		this.Input = new input();
		this.Playlist = new playlist();
		this.Transport = new transport();
		this.Transport.setQueue(this.Playlist);
		this.ResourceController = new resourceController();
		this.Websocket = new websocket();
		this.MediaLib = new mediaLib();
		var timeview = new timeView();

	};

	this.attach = function(event, listener){
		Listeners[event].push(listener);
	};
	this.detach = function(event, listener){
		//slice listerner out of array event
	};
	this.notify = function(event){
		switch(event){
			case "onStateChanged":
				for(var i in Listeners.onStateChanged){
					Listeners.onStateChanged[i](arguments[1]);
				}
				break;	
			case "onPositionChanged":
				for(var i in Listeners.onPositionChanged){
					Listeners.onPositionChanged[i](arguments[1]);
				}
				break;
			default:
				for(var i in Listeners[event]){
					Listeners[event][i](arguments[1]);
				}
				break;
		}
	};
	this.getAnalyser = function(){
		return this.Transport.getAnalyser();
	};
	
}